<script>
$(document).ready(function(){
	$('#sortForm').ajaxForm({
		success:       showResponse
		});
	function showResponse() {
		jAlert('<?php echo $this->translate("completed")?>');
	}
	$("#sortable tbody.content").sortable();
    $("#sortable tbody.content").disableSelection();
    $("#autoSignBtn").click(function(){
        $.each($("#sortable .numbers"), function(i,v){
            $(v).attr('value',i+1);
         });
        $('#sortForm').submit();
     });

    // 儲存座號
    $("#saveBtn").click(function(){
    	$('#sortForm').submit();
        $("#select-subject").trigger('change');
     });

    $(".deleteBtn").click(function(){
    	   var id = $(this).attr('id').substr(7);
    	   var selTr = $(this).parents('tr');
    	   $.getJSON("<?php echo $this->route('delete')?>",{sn:id},function(){
               //jAlert("<?php echo $this->translate('deleted')?>");
               selTr.fadeOut('slow').remove();
         });
    });
});
</script>
<style>
#sortable tbody td {padding:1px}
</style>
<?php if($this->data):?>
<form id="sortForm" action="<?php echo $this->route('sort-number')?>" method="post">
<input type="button"  id="autoSignBtn" class="fg-button ui-state-default ui-corner-all "
value="<?php echo $this->translate('auto sign number')?>" style="margin:1px;font-size:11px" />
<input type="button"  id="saveBtn" class="fg-button ui-corner-all ui-state-default "
value="<?php echo $this->translate('save number')?>" style="margin:1px;font-size:11px" />
<table id="sortable" class="hor-minimalist-b">
<thead>
<tr>
<th></th>
<th><?php echo $this->translate('number')?>
</th>
<th><?php echo $this->translate('student_id')?></th>
<th><?php echo $this->translate('student_name')?></th>
<th><?php echo $this->translate('student_number')?></th>
<th></th>
</tr>
</thead>
<tbody class="content">
<?php $temp = $this->data[0]['class_sn']; $i=0?>
<?php foreach($this->data as $row):?>
<?php if ($row['class_sn'] <> $temp) {$temp = $row['class_sn']; $i++;}?>
<tr class="<?php if ($i%2 == 0):?>even<?php else:?>odd<?php endif?>">
<td><span class="ui-icon ui-icon-arrowthick-2-n-s"></span></td>
<td><input type="text"  class="numbers"  name="numbers[<?php echo $row['student_sn']?>]"
value="<?php echo $row['number']?>" size="3" /></td>
<td><?php echo $row['student_id']?></td>
<td><?php echo $row['name']?></td>
<td><?php echo $row['class_sn']?> - <?php echo $row['student_number']?></td>
<td><span class="deleteBtn ui-icon ui-icon-close"  id="delete-<?php echo $row['sn']?>" title="remove this student"></span></td>
</tr>
<?php endforeach;?>
</tbody>
</table>
<input type="hidden" name="group_sn" value="<?php echo $this->group_sn?>" />
</form>
<?php endif?>